package com.lanou.pianke.admin.web.controller;

import com.lanou.pianke.admin.service.PieceTagService;
import com.lanou.pianke.piecetag.web.entity.PieceTag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/admin/")
@RestController
public class PieceTagController {

    @Autowired
    private PieceTagService pieceTagService;

    @GetMapping("showPieceTags")
    public List<PieceTag> showPieceTags(){
        List<PieceTag> pieceTagList = pieceTagService.showAll();
        return pieceTagList;
    }

    // 增加分类
    @PostMapping("addPieceTag/{tagname}&{tagimg}")
    public String addPieceTag(@PathVariable String tagname, @PathVariable String tagimg){
        PieceTag pieceTag = new PieceTag(tagname,tagimg);
        pieceTagService.addTag(pieceTag);
        return "添加分类成功";
    }

    // 删除分类
    @DeleteMapping("deletePieceTag/{tagid}")
    public String deletePieceTag(@PathVariable Long tagid){
        pieceTagService.deletByTagid(tagid);
        return "删除碎片分类成功";
    }


}
